<?php
/**
 * Created by PhpStorm.
 * User: Sunqj
 * Date: 2017/2/12
 * Time: 下午12:21
 */
namespace app\bussiness\controller;

use app\common\model\Settings;
use think\Image;

class Poster extends Common
{
    //
    public function index()
    {
        return $this->fetch();
    }

    //推广海报
    public function spread()
    {
        //渲染
        if (request()->isGet())
        {
            //标题
            $this->templateTitle('推广海报');

            //获取配置
            $settings = Settings::getSettings(H_SETTINGS_POSTER_SPREAD);

            $this->assign("settings", $settings);

            return $this->fetch();
        }

        //处理
        if (request()->isAjax())
        {
            //
            $params = request()->post();

            //获取背景图
            $background = $params["background"];

            //获取图片信息
            $image = Image::open(ROOT_PATH . 'public' . '/' . $background);
            $size = $image->size();

            //判断背景图
            if ($size[0] != 640 || $size[1] != 1008)
            {
                $this->ajaxError(translate("Poster-spread:wrong_size"));
            }

            //存储设置
            Settings::setSettings(H_SETTINGS_POSTER_SPREAD, $params);

            $this->ajaxSuccess(translate("Poster-spread:success"));
        }
    }
}